package net.csdra.DongPoShuZiTuShuGuan.service;

import net.csdra.DongPoShuZiTuShuGuan.domain.PlayInfo;
import net.csdra.DongPoShuZiTuShuGuan.domain.PlayInfoRepository;
import net.csdra.DongPoShuZiTuShuGuan.domain.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * Created by add on 2018/1/17.
 */
@Service
public class PlayInfoServiceImpl implements PlayInfoService {

    @Autowired
    PlayInfoRepository playInfoRepository;
    @Autowired
    VideoRepository videoRepository;

    @Override
    public PlayInfo getPlayInfo() {
        List<PlayInfo> playInfos = this.playInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
            return criteriaQuery.orderBy(criteriaBuilder.asc(root.get("createTime"))).getRestriction();
        });
        Assert.state(playInfos.size() > 0, "@未设置在播视频");
        return playInfos.get(0);
    }
}
